*------------------------------------------------------------------------------*
*																			   *
*				Time of Final Vote Decision								   	   *
*																			   *
*------------------------------------------------------------------------------*

* Project: "Voting in Context" Book
* Title: "Always late? Stability and change in individuals‘ time of vote decisions"
* Author: Maria Preißinger 
* Date: 17.08.15


*------------------------------------------
* Voting Intention (second vote)
*------------------------------------------

labelbook V986_A			// use this labelbook with few changes for 2009 and 2013
	
lab copy V986_A parties 	// copy

lab define parties ///			and make our changes
 8888 "weiß nicht" ///
 9999 "werde nicht wählen" ///
 322 "AfD" ///
 801 "andere Partei", add
 
 labelbook parties 				//get overview


* code vote intention for waves 1-6  
foreach welle of numlist 1/6 {
	gen a_wabsfull`welle' = a_kp`welle'_190bc
	recode a_wabsfull`welle'  (803 804 993 997 999 1000=.) (998=8888) 
	replace a_wabsfull`welle' = 9999 if a_kp`welle'_170==4 ///
		| a_kp`welle'_170==5 | a_kp`welle'_170==98 
	gen b_wabsfull`welle' = b_kp`welle'_190bb
	recode b_wabsfull`welle' (-99 -97 -95 -93=.) (-98=8888) 
	replace b_wabsfull`welle' = 9999 if b_kp`welle'_170==4 ///
		| b_kp`welle'_170==5 
	lab var a_wabsfull`welle' "Wahlabsicht mit allen Parteien + Briefwähler + Nichtwähler"
	lab var b_wabsfull`welle' "Wahlabsicht mit allen Parteien + Briefwähler + Nichtwähler"
}

lab val ?_wabsfull? parties


* real vote wave 7
gen a_wabsfull7 = a_kp7_200bc
recode a_wabsfull7 (803 804 993 997 998 999 1000=.) //"weiß nicht" zählt in Nachwahl zu Missing
replace a_wabsfull7 = 9999 if a_kp7_180==2 | a_kp7_200bc==994 

gen b_wabsfull7 = b_kp7_200bb
recode b_wabsfull7 (-99 -97 -95 -93=.) 
replace b_wabsfull7 = 9999 if b_kp7_180==2 | b_kp7_200bb==-84

lab var a_wabsfull7 "Tatsächliche Wahl"
lab var b_wabsfull7 "Tatsächliche Wahl"
lab val *wabsfull7 parties


* integrate postal voters
//2009
//problem: no dependent interviewing, first interview counts as postal vote,
//thereafter fixed at this value
foreach welle of numlist 3/7 {
replace a_wabsfull`welle'= a_kp3_191bc if a_kp3_170==6
}

foreach welle of numlist 4/7 {
replace a_wabsfull`welle' = a_kp4_191bc if a_kp4_170==6 & a_kp3_170~=6
}

foreach welle of numlist 5/7 {
replace a_wabsfull`welle' = a_kp5_191bc if a_kp5_170==6 & a_kp4_170~=6 & a_kp3_170~=6
}

foreach welle of numlist 6/7 {
replace a_wabsfull`welle' = a_kp6_191bc if a_kp6_170==6 & a_kp5_170~=6 & a_kp4_170~=6 & a_kp3_170~=6
}

foreach welle of numlist 3/7 {
recode a_wabsfull`welle' (997 998 999=.)  //postal voters must not say "don't know"
}

tab1 a_wabsfull?


//2013: dependent interviewing was implemented
foreach welle of numlist 3/6 {			
replace b_wabsfull`welle' = b_kp`welle'_191bb if b_kp`welle'_170==6
recode b_wabsfull`welle' (-99 -95 -93=.)
}


replace b_wabsfull7 = b_kp7_191bb if b_kp7_180==6
recode b_wabsfull7 (-99 -95 -93=.)

foreach welle of numlist 4/7 {
replace b_wabsfull`welle' = b_wabsfull3 if b_kp3_170==6
}

foreach welle of numlist 5/7 {
replace b_wabsfull`welle' = b_wabsfull4 if b_kp4_170==6
}

foreach welle of numlist 6/7 {
replace b_wabsfull`welle' = b_wabsfull5 if b_kp5_170==6
}

foreach welle of numlist 7/7 {
replace b_wabsfull`welle' = b_wabsfull6 if b_kp6_170==6
}

tab1 ?_wabsfull?

tab b_wabsfull1 wkp0913, m


* party dummies for each wave
foreach year in a b {
foreach welle of numlist 1/7 {
gen `year'_votecdu`welle' = `year'_wabsfull`welle'==1
gen `year'_votespd`welle' = `year'_wabsfull`welle'==4
gen `year'_votefdp`welle' = `year'_wabsfull`welle'==5
gen `year'_votegru`welle' = `year'_wabsfull`welle'==6
gen `year'_votelink`welle' = `year'_wabsfull`welle'==7
}
}

foreach year in a b {
foreach party in cdu spd fdp gru link {
foreach welle of numlist 1/7 {
replace `year'_vote`party'`welle' = . if `year'_wabsfull`welle'==.
}
}
}

tab b_wabsfull7 b_votecdu7, m


*-----------------------------------------------------------
* Time of Final Decision
*------------------------------------------------------

/* 
Time of final vote decision is defined as the point in time after which the 
vote intention does not change anymore.

dk=don't know

dk dk CDU FDP CDU CDU CDU  
final decision did not change starting from wave 5. timedeci=5

dk dk dk dk dk dk CDU
final decision changed the last time in wave 7. timedeci=7

CDU CDU CDU CDU CDU CDU CDU 
final decision is constant throughout all waves. timedeci=1


1st Version timedeci:
Only for respondents, who have valid observations in all waves.
BUT: 2009 Wave 2-Starter are integrated; these respondents were able to take a final
decision in wave 2 at the earliest.

Coding-Strategy: 
"egen" with diff-Function & "!missing" facilitate the coding
If all final decisions are equal in all waves, then timedeci==1
If final decision wave 1 unequal wave 2, but wave 2-wave 7 all equal, then timedeci==2
If final decision 2 unequal to 3, but from wave 3 to wave 7 alll equal, then timedeci=3
(Value does not matter, only cannot be missing)

2nd Version timedeci:
also for respondents with single missings in between two valid observations
(hence, missing value in W2, W3, W4, W5 or W6).

If we have the following pattern:
(CDU) (CDU) (FDP) (Missing) (CDU) (CDU) (CDU) 
and we assume that missing value=FDP, then timedeci=5.

And if we have the following pattern 
(CDU) (CDU) (CDU) (Missing) (CDU) (CDU) (CDU)
and assume that missing value=CDU, then timedeci=1

rule: If missing value is surrounded by missing values, then we assume that 
missing = final decision in preceding wave
*/


********
* 2013 *
********

* 1. Version: no missing replacement
*********

egen b_help1 = diff(b_wabsfull?) if !missing(b_wabsfull1, ///
	b_wabsfull2, b_wabsfull3, b_wabsfull4, b_wabsfull5, b_wabsfull6, ///
	b_wabsfull7)
egen b_help2 = diff(b_wabsfull2 b_wabsfull3 b_wabsfull4 b_wabsfull5 ///
	b_wabsfull6 b_wabsfull7) if !missing(b_wabsfull1, ///
	b_wabsfull2, b_wabsfull3, b_wabsfull4, b_wabsfull5, b_wabsfull6, ///
	b_wabsfull7)
egen b_help3 = diff(b_wabsfull3 b_wabsfull4 b_wabsfull5 ///
	b_wabsfull6 b_wabsfull7) if !missing(b_wabsfull1, ///
	b_wabsfull2, b_wabsfull3, b_wabsfull4, b_wabsfull5, b_wabsfull6, ///
	b_wabsfull7)
egen b_help4 = diff(b_wabsfull4 b_wabsfull5 ///
	b_wabsfull6 b_wabsfull7) if !missing(b_wabsfull1, ///
	b_wabsfull2, b_wabsfull3, b_wabsfull4, b_wabsfull5, b_wabsfull6, ///
	b_wabsfull7)
egen b_help5 = diff(b_wabsfull5 b_wabsfull6 b_wabsfull7) if !missing(b_wabsfull1, ///
	b_wabsfull2, b_wabsfull3, b_wabsfull4, b_wabsfull5, b_wabsfull6, ///
	b_wabsfull7)
egen b_help6 = diff(b_wabsfull6 b_wabsfull7) if !missing(b_wabsfull1, ///
	b_wabsfull2, b_wabsfull3, b_wabsfull4, b_wabsfull5, b_wabsfull6, ///
	b_wabsfull7)
gen b_help7 = 0 if !missing(b_wabsfull1, ///
	b_wabsfull2, b_wabsfull3, b_wabsfull4, b_wabsfull5, b_wabsfull6, ///
	b_wabsfull7)
	
tab b_help1
tab b_help2
tab b_help3
tab b_help4
tab b_help5
tab b_help6
tab b_help7, m

list b_help1 b_wabsfull1 b_wabsfull2 b_wabsfull3 b_wabsfull4 b_wabsfull5 ///
	b_wabsfull6 b_wabsfull7 in 1/150

	
* code "time of final decision"-variable, without missing replacement	
gen b_timedeci1=1 if b_help1==0
replace b_timedeci1=2 if b_help1==1 & b_help2==0
replace b_timedeci1=3 if b_help1==1 & b_help2==1 & b_help3==0
replace b_timedeci1=4 if b_help1==1 & b_help2==1 & b_help3==1 & b_help4==0
replace b_timedeci1=5 if b_help1==1 & b_help2==1 & b_help3==1 & b_help4==1 ///
	& b_help5==0
replace b_timedeci1=6 if b_help1==1 & b_help2==1 & b_help3==1 & b_help4==1 ///
	& b_help5==1 & b_help6==0
replace b_timedeci1=7 if b_help1==1 & b_help2==1 & b_help3==1 & b_help4==1 ///
	& b_help5==1 & b_help6==1 & b_help7==0
	
fre b_timedeci1

list b_timedeci1 b_help1 b_help2 b_help3 b_help4 b_help5 b_help6 b_help7 in 1/100

lab var b_timedeci1 "Time of Final Decision 2013 (w/o replacing missings)"
lab define timedeci_lab 1 "wave 1" 2 "wave 2" 3 "wave 3" 4 "wave 4" 5 "wave 5" ///
	6 "wave 6" 7 "wave 7"
lab value b_timedeci1 timedeci_lab


* 2. Version: Missing replacement
*******

foreach wave of num 1/7{
gen b_wabshelp`wave' = b_wabsfull`wave'
}

tab b_wabshelp2 b_wabsfull2

foreach wave of num 2/6{
local w_minus = `wave'-1
local w_plus = `wave'+1
replace b_wabshelp`wave' = b_wabsfull`w_minus' if !missing(b_wabsfull`w_minus', ///
	b_wabsfull`w_plus') & b_wabsfull`wave'==.  
}


tab b_wabshelp3 b_wabsfull2 if b_wabsfull2~=. & b_wabsfull4~=. & b_wabsfull3==., m

egen b_help2_w1 = diff(b_wabshelp?) if !missing(b_wabshelp1, ///
	b_wabshelp2, b_wabshelp3, b_wabshelp4, b_wabshelp5, b_wabshelp6, ///
	b_wabshelp7)
egen b_help2_w2 = diff(b_wabshelp2 b_wabshelp3 b_wabshelp4 b_wabshelp5 ///
	b_wabshelp6 b_wabshelp7) if !missing(b_wabshelp1, ///
	b_wabshelp2, b_wabshelp3, b_wabshelp4, b_wabshelp5, b_wabshelp6, ///
	b_wabshelp7)
egen b_help2_w3 = diff(b_wabshelp3 b_wabshelp4 b_wabshelp5 ///
	b_wabshelp6 b_wabshelp7) if !missing(b_wabshelp1, ///
	b_wabshelp2, b_wabshelp3, b_wabshelp4, b_wabshelp5, b_wabshelp6, ///
	b_wabshelp7)
egen b_help2_w4 = diff(b_wabshelp4 b_wabshelp5 ///
	b_wabshelp6 b_wabshelp7) if !missing(b_wabshelp1, ///
	b_wabshelp2, b_wabshelp3, b_wabshelp4, b_wabshelp5, b_wabshelp6, ///
	b_wabshelp7)
egen b_help2_w5 = diff(b_wabshelp5 b_wabshelp6 b_wabshelp7) if !missing(b_wabshelp1, ///
	b_wabshelp2, b_wabshelp3, b_wabshelp4, b_wabshelp5, b_wabshelp6, ///
	b_wabshelp7)
egen b_help2_w6 = diff(b_wabshelp6 b_wabshelp7) if !missing(b_wabshelp1, ///
	b_wabshelp2, b_wabshelp3, b_wabshelp4, b_wabshelp5, b_wabshelp6, ///
	b_wabshelp7)
gen b_help2_w7 = 0 if !missing(b_wabshelp1, ///
	b_wabshelp2, b_wabshelp3, b_wabshelp4, b_wabshelp5, b_wabshelp6, ///
	b_wabshelp7)
	
tab b_help2_w1
tab b_help2_w2
tab b_help2_w3
tab b_help2_w4
tab b_help2_w5
tab b_help2_w6
tab b_help2_w7

list b_help2_w1 b_help2_w2 b_help2_w6 b_wabshelp1 b_wabshelp2 b_wabshelp3 b_wabshelp4 b_wabshelp5 ///
	b_wabshelp6 b_wabshelp7 in 1/300

	
* code "time of final decision"-variable with replaced missing	
gen b_timedeci2=1 if b_help2_w1==0
replace b_timedeci2=2 if b_help2_w1==1 & b_help2_w2==0
replace b_timedeci2=3 if b_help2_w1==1 & b_help2_w2==1 & b_help2_w3==0
replace b_timedeci2=4 if b_help2_w1==1 & b_help2_w2==1 & b_help2_w3==1 & b_help2_w4==0
replace b_timedeci2=5 if b_help2_w1==1 & b_help2_w2==1 & b_help2_w3==1 & b_help2_w4==1 ///
	& b_help2_w5==0
replace b_timedeci2=6 if b_help2_w1==1 & b_help2_w2==1 & b_help2_w3==1 & b_help2_w4==1 ///
	& b_help2_w5==1 & b_help2_w6==0
replace b_timedeci2=7 if b_help2_w1==1 & b_help2_w2==1 & b_help2_w3==1 & b_help2_w4==1 ///
	& b_help2_w5==1 & b_help2_w6==1 & b_help2_w7==0
	
fre b_timedeci1 b_timedeci2  //we gain about 500 cases
							//aggregated propotions change slightly:
							//less stables, more unstables

list b_wabsfull? if b_timedeci1==. & b_timedeci2~=., nol  
list b_timedeci2 b_help2_w1 b_help2_w2 b_help2_w3 b_help2_w4 b_help2_w5 b_help2_w6 b_help2_w7 in 1/100

lab var b_timedeci2 "Time of Final Decision 2013 (replacing missings)"
lab value b_timedeci2 timedeci_lab

fre b_timedeci2 


* Combine Waves 1 & 2

/* For measurement to be comparable across 2009 and 2013, decision times in wave 1
and wave2 have jo be joined */

gen b_timedeci1b = b_timedeci1
replace b_timedeci1b = 2 if b_timedeci1==1
lab var b_timedeci1b "Time of Final Decision 2013 (wave 1 & 2 joined; w/o replacing missings)"
lab value b_timedeci1b timedeci_lab
tab b_timedeci1b b_timedeci1
 
gen b_timedeci2b = b_timedeci2
replace b_timedeci2b = 2 if b_timedeci2==1
lab var b_timedeci2b "Time of Final Decision 2013 (wave 1 & 2 joined; replacing missings)"
lab value b_timedeci2b timedeci_lab
tab b_timedeci2b b_timedeci2  
 

 
********
* 2009 *
********

* 1. Version, no missing replacement
*******

egen a_help1 = diff(a_wabsfull?) if !missing(a_wabsfull1, ///
	a_wabsfull2, a_wabsfull3, a_wabsfull4, a_wabsfull5, a_wabsfull6, ///
	a_wabsfull7)
tab a_help1 if a_w1 == 0, mis
tab a_w1
	
egen a_help2 = diff(a_wabsfull2 a_wabsfull3 a_wabsfull4 a_wabsfull5 ///
	a_wabsfull6 a_wabsfull7) if !missing(a_wabsfull1, ///
	a_wabsfull2, a_wabsfull3, a_wabsfull4, a_wabsfull5, a_wabsfull6, ///
	a_wabsfull7) | (a_w1==0 & !missing(a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull5, a_wabsfull6, a_wabsfull7))
tab a_help2 if a_w1 == 0, mis
list a_help2 a_wabsfull1 a_wabsfull2 a_wabsfull3 a_wabsfull4 a_wabsfull5 ///
	a_wabsfull6 a_wabsfull7 if a_w1 == 0

egen a_help3 = diff(a_wabsfull3 a_wabsfull4 a_wabsfull5 ///
	a_wabsfull6 a_wabsfull7) if !missing(a_wabsfull1, ///
	a_wabsfull2, a_wabsfull3, a_wabsfull4, a_wabsfull5, a_wabsfull6, ///
	a_wabsfull7) | (a_w1==0 & !missing(a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull5, a_wabsfull6, a_wabsfull7))
	
egen a_help4 = diff(a_wabsfull4 a_wabsfull5 ///
	a_wabsfull6 a_wabsfull7) if !missing(a_wabsfull1, ///
	a_wabsfull2, a_wabsfull3, a_wabsfull4, a_wabsfull5, a_wabsfull6, ///
	a_wabsfull7) | (a_w1==0 & !missing(a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull5, a_wabsfull6, a_wabsfull7))
	
egen a_help5 = diff(a_wabsfull5 a_wabsfull6 a_wabsfull7) if !missing(a_wabsfull1, ///
	a_wabsfull2, a_wabsfull3, a_wabsfull4, a_wabsfull5, a_wabsfull6, ///
	a_wabsfull7) | (a_w1==0 & !missing(a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull5, a_wabsfull6, a_wabsfull7))
	
egen a_help6 = diff(a_wabsfull6 a_wabsfull7) if !missing(a_wabsfull1, ///
	a_wabsfull2, a_wabsfull3, a_wabsfull4, a_wabsfull5, a_wabsfull6, ///
	a_wabsfull7) | (a_w1==0 & !missing(a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull5, a_wabsfull6, a_wabsfull7))
	
gen a_help7 = 0 if !missing(a_wabsfull1, ///
	a_wabsfull2, a_wabsfull3, a_wabsfull4, a_wabsfull5, a_wabsfull6, ///
	a_wabsfull7) | (a_w1==0 & !missing(a_wabsfull2, a_wabsfull3, ///
	a_wabsfull4, a_wabsfull5, a_wabsfull6, a_wabsfull7))
	
tab a_help1
tab a_help2
tab a_help3
tab a_help4
tab a_help5
tab a_help6
tab a_help7

list a_help1 a_wabsfull1 a_wabsfull2 a_wabsfull3 a_wabsfull4 a_wabsfull5 ///
	a_wabsfull6 a_wabsfull7 in 4500/4650

	
	
* code "time of final decision"-variable, without missing replacement	
gen a_timedeci1=1 if a_help1==0
replace a_timedeci1=2 if a_help1==1 & a_help2==0
replace a_timedeci1=3 if a_help1==1 & a_help2==1 & a_help3==0
replace a_timedeci1=4 if a_help1==1 & a_help2==1 & a_help3==1 & a_help4==0
replace a_timedeci1=5 if a_help1==1 & a_help2==1 & a_help3==1 & a_help4==1 ///
	& a_help5==0
replace a_timedeci1=6 if a_help1==1 & a_help2==1 & a_help3==1 & a_help4==1 ///
	& a_help5==1 & a_help6==0
replace a_timedeci1=7 if a_help1==1 & a_help2==1 & a_help3==1 & a_help4==1 ///
	& a_help5==1 & a_help6==1 & a_help7==0
	
replace a_timedeci1=2 if a_help1==. & a_help2==0 & a_w1==0 //include w2-starters
replace a_timedeci1=3 if a_help1==. & a_help2==1 & a_help3==0 & a_w1==0
replace a_timedeci1=4 if a_help1==. & a_help2==1 & a_help3==1 & a_help4==0 & a_w1==0
replace a_timedeci1=5 if a_help1==. & a_help2==1 & a_help3==1 & a_help4==1 ///
	& a_help5==0 & a_w1==0
replace a_timedeci1=6 if a_help1==. & a_help2==1 & a_help3==1 & a_help4==1 ///
	& a_help5==1 & a_help6==0 & a_w1==0
replace a_timedeci1=7 if a_help1==. & a_help2==1 & a_help3==1 & a_help4==1 ///
	& a_help5==1 & a_help6==1 & a_help7==0 & a_w1==0
	
list a_timedeci1 a_help1 a_help2 a_help3 a_help4 a_help5 a_help6 a_help7 in 5000/5150

lab var a_timedeci1 "Time of Final Decision 2009 (w/o replacing missings)"
lab value a_timedeci1 timedeci_lab

tab a_timedeci1


* 2. Version: Missings being replaced
**********

foreach wave of num 1/7{
gen a_wabshelp`wave' = a_wabsfull`wave'
}

tab a_wabshelp2 a_wabsfull2

foreach wave of num 2/6{
local w_minus = `wave'-1
local w_plus = `wave'+1
replace a_wabshelp`wave' = a_wabsfull`w_minus' if !missing(a_wabsfull`w_minus', ///
	a_wabsfull`w_plus') & a_wabsfull`wave'==.
}



	
egen a_help2_w1 = diff(a_wabshelp?) if !missing(a_wabshelp1, ///
	a_wabshelp2, a_wabshelp3, a_wabshelp4, a_wabshelp5, a_wabshelp6, ///
	a_wabshelp7) 
	
egen a_help2_w2 = diff(a_wabshelp2 a_wabshelp3 a_wabshelp4 a_wabshelp5 ///
	a_wabshelp6 a_wabshelp7) if !missing(a_wabshelp1, ///
	a_wabshelp2, a_wabshelp3, a_wabshelp4, a_wabshelp5, a_wabshelp6, ///
	a_wabshelp7) | (a_w1==0 & !missing(a_wabshelp2, a_wabshelp3, ///
	a_wabshelp4, a_wabshelp5, a_wabshelp6, a_wabshelp7))
	
egen a_help2_w3 = diff(a_wabshelp3 a_wabshelp4 a_wabshelp5 ///
	a_wabshelp6 a_wabshelp7) if !missing(a_wabshelp1, ///
	a_wabshelp2, a_wabshelp3, a_wabshelp4, a_wabshelp5, a_wabshelp6, ///
	a_wabshelp7) | (a_w1==0 & !missing(a_wabshelp2, a_wabshelp3, ///
	a_wabshelp4, a_wabshelp5, a_wabshelp6, a_wabshelp7))
	
egen a_help2_w4 = diff(a_wabshelp4 a_wabshelp5 ///
	a_wabshelp6 a_wabshelp7) if !missing(a_wabshelp1, ///
	a_wabshelp2, a_wabshelp3, a_wabshelp4, a_wabshelp5, a_wabshelp6, ///
	a_wabshelp7) | (a_w1==0 & !missing(a_wabshelp2, a_wabshelp3, ///
	a_wabshelp4, a_wabshelp5, a_wabshelp6, a_wabshelp7))
	
egen a_help2_w5 = diff(a_wabshelp5 a_wabshelp6 a_wabshelp7) if !missing(a_wabshelp1, ///
	a_wabshelp2, a_wabshelp3, a_wabshelp4, a_wabshelp5, a_wabshelp6, ///
	a_wabshelp7) | (a_w1==0 & !missing(a_wabshelp2, a_wabshelp3, ///
	a_wabshelp4, a_wabshelp5, a_wabshelp6, a_wabshelp7))
	
egen a_help2_w6 = diff(a_wabshelp6 a_wabshelp7) if !missing(a_wabshelp1, ///
	a_wabshelp2, a_wabshelp3, a_wabshelp4, a_wabshelp5, a_wabshelp6, ///
	a_wabshelp7) | (a_w1==0 & !missing(a_wabshelp2, a_wabshelp3, ///
	a_wabshelp4, a_wabshelp5, a_wabshelp6, a_wabshelp7))
	
gen a_help2_w7 = 0 if !missing(a_wabshelp1, ///
	a_wabshelp2, a_wabshelp3, a_wabshelp4, a_wabshelp5, a_wabshelp6, ///
	a_wabshelp7) | (a_w1==0 & !missing(a_wabshelp2, a_wabshelp3, ///
	a_wabshelp4, a_wabshelp5, a_wabshelp6, a_wabshelp7))
	
tab a_help2_w1
tab a_help2_w2
tab a_help2_w3
tab a_help2_w4
tab a_help2_w5
tab a_help2_w6
tab a_help2_w7

list a_help2_w1 a_help2_w2 a_help2_w6 a_wabshelp1 a_wabshelp2 a_wabshelp3 a_wabshelp4 a_wabshelp5 ///
	a_wabshelp6 a_wabshelp7 in 5000/5300
	

	
* code "time of final decision"-variable with missing replacement
gen a_timedeci2=1 if a_help2_w1==0
replace a_timedeci2=2 if a_help2_w1==1 & a_help2_w2==0
replace a_timedeci2=3 if a_help2_w1==1 & a_help2_w2==1 & a_help2_w3==0
replace a_timedeci2=4 if a_help2_w1==1 & a_help2_w2==1 & a_help2_w3==1 & a_help2_w4==0
replace a_timedeci2=5 if a_help2_w1==1 & a_help2_w2==1 & a_help2_w3==1 & a_help2_w4==1 ///
	& a_help2_w5==0
replace a_timedeci2=6 if a_help2_w1==1 & a_help2_w2==1 & a_help2_w3==1 & a_help2_w4==1 ///
	& a_help2_w5==1 & a_help2_w6==0
replace a_timedeci2=7 if a_help2_w1==1 & a_help2_w2==1 & a_help2_w3==1 & a_help2_w4==1 ///
	& a_help2_w5==1 & a_help2_w6==1 & a_help2_w7==0

replace a_timedeci2=2 if a_help2_w1==. & a_help2_w2==0 & a_w1==0  //include w2-starters
replace a_timedeci2=3 if a_help2_w1==. & a_help2_w2==1 & a_help2_w3==0 & a_w1==0
replace a_timedeci2=4 if a_help2_w1==. & a_help2_w2==1 & a_help2_w3==1 & a_help2_w4==0 & a_w1==0
replace a_timedeci2=5 if a_help2_w1==. & a_help2_w2==1 & a_help2_w3==1 & a_help2_w4==1  ///
	& a_help2_w5==0 & a_w1==0
replace a_timedeci2=6 if a_help2_w1==. & a_help2_w2==1 & a_help2_w3==1 & a_help2_w4==1 ///
	& a_help2_w5==1 & a_help2_w6==0 & a_w1==0
replace a_timedeci2=7 if a_help2_w1==. & a_help2_w2==1 & a_help2_w3==1 & a_help2_w4==1 ///
	& a_help2_w5==1 & a_help2_w6==1 & a_help2_w7==0 & a_w1==0

list a_timedeci2 a_help2_w1 a_help2_w2 a_help2_w3 a_help2_w4 a_help2_w5 a_help2_w6 a_help2_w7 in 7001/7100

lab var a_timedeci2 "Time of Final Decision 2009 (replacing missings)"
lab value a_timedeci2 timedeci_lab

tab a_timedeci2


* Combine Waves 1 & 2
gen a_timedeci1b = a_timedeci1
replace a_timedeci1b = 2 if a_timedeci1==1
lab var a_timedeci1b "Time of Final Decision 2009 (wave 1 & 2 joined; w/o replacing missings)"
lab value a_timedeci1b timedeci_lab
tab a_timedeci1b a_timedeci1
 
gen a_timedeci2b = a_timedeci2
replace a_timedeci2b = 2 if a_timedeci2==1
lab var a_timedeci2b "Time of Final Decision 2009 (wave 1 & 2 joined; replacing missings)"
lab value a_timedeci2b timedeci_lab
tab a_timedeci2b a_timedeci2 



*---------------------------------
* Timedeci Dummy for each wave
*-----------------------------------

foreach year in a b {
foreach wave of numlist 2/7 {
gen `year'_decided`wave' = 0 if `year'_timedeci2b>`wave'
replace `year'_decided`wave' = 1 if `year'_timedeci2b<=`wave'
replace `year'_decided`wave' = . if `year'_timedeci2b==.

gen `year'_decidedm`wave' = 0 if `year'_timedeci1b>`wave'
replace `year'_decidedm`wave' = 1 if `year'_timedeci1b<=`wave'
replace `year'_decidedm`wave' = . if `year'_timedeci1b==.
}
}



